package com.example.administrator.yuejian_2.fragment;


<<<<<<< HEAD
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.StaggeredGridLayoutManager;
=======
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
>>>>>>> b079ae49aea3652b48f9c84201c89333c2f216f2
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
<<<<<<< HEAD
import android.widget.ImageButton;

import com.example.administrator.yuejian_2.R;
import com.example.administrator.yuejian_2.activity.PostAddActivity;
import com.example.administrator.yuejian_2.adapter.PoListAdapter;
import com.example.administrator.yuejian_2.bean.PostListBean;
import com.example.administrator.yuejian_2.interservice.Const;
import com.example.administrator.yuejian_2.interservice.PostService;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
=======

import com.example.administrator.yuejian_2.R;
>>>>>>> b079ae49aea3652b48f9c84201c89333c2f216f2

/**
 * A simple {@link Fragment} subclass.
 */
public class PostFragment extends Fragment {
<<<<<<< HEAD
    private RecyclerView recyclerView;
    private PoListAdapter adapter;
    private ImageButton imageButton;
=======
    private GridView gridView;

    private int images[] = {R.drawable.fly,R.drawable.fly,R.drawable.fly};

>>>>>>> b079ae49aea3652b48f9c84201c89333c2f216f2

    public PostFragment() {
        // Required empty public constructor
    }

    @Override
<<<<<<< HEAD
=======
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        gridView = view.findViewById(R.id.po_GridView);

    }

    @Override
>>>>>>> b079ae49aea3652b48f9c84201c89333c2f216f2
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_post, container, false);
    }

<<<<<<< HEAD
    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

        recyclerView = view.findViewById(R.id.post_recyclerView);
        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl(Const.BASE_URL)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
        PostService service = retrofit.create(PostService.class);
        Call<List<PostListBean>> call = service.shaitulist();
        call.enqueue(new Callback<List<PostListBean>>() {
            @Override
            public void onResponse(Call<List<PostListBean>> call, Response<List<PostListBean>> response) {
                if (getActivity() == null)
                    return;
                adapter = new PoListAdapter(getActivity(),response.body());
                StaggeredGridLayoutManager recyclerViewLayoutManager =
                new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL);
                recyclerView.setLayoutManager(recyclerViewLayoutManager);
                recyclerView.setAdapter(adapter);
                recyclerView.setItemAnimator(new DefaultItemAnimator());


            }

            @Override
            public void onFailure(Call<List<PostListBean>> call, Throwable t) {

            }
        });

        imageButton = view.findViewById(R.id.post_add);
        imageButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(getActivity(), PostAddActivity.class);
                getActivity().startActivity(intent);
            }
        });
    }
=======
>>>>>>> b079ae49aea3652b48f9c84201c89333c2f216f2
}
